export const sortTree = function(tree, arr){ // 剔除不需要字段,根据 arr 字段排序
  if (!tree||!tree.length) {return false}
  let result = []
  for (let i = 0; i < tree.length; i++) {
    const item = tree[i];
    let obj ={}
    arr.map(val => {
      obj[val] = item[val]
    })
    if(item.children&&item.children.length){
      obj.children = []
      item.children.map(ele =>{
        let childrenObj = {}
        arr.map(val => {
          childrenObj[val] = ele[val]
        })
        obj.children.push(childrenObj)
      })
    }
    obj.isOpen = false
    result.push(obj)
  }
  return result
}

export const appendFeild = function (array,feild,value){ // 为数组每一项添加一个字段
  const length = array.length
  for (let i = 0; i < length; i++) {
    const element = array[i];
    element[feild] = value
  }
  return array
}

export  function getUrlKey(name){ //获取地址栏参数
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}
export function ArrayIsEmputy (value){
  if (value === undefined || value === null || value === '' || value.length === 0) {
    return true
  } else {
    return false
  }
}

export function turnHref(url){ // url跳转,a标签会认为是route进行跳转,外部链接需要用js来实现跳转
  window.location.href = url;
}